#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <math.h>
#include <typeinfo>
#include <fstream>
#include <cassert>
#include "json/json.h"
#include "thread"

#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>

#include "opencv_extend.h"
#include "serial.h"
#include "log.h"
#include"sentry.h"
#include"infantry.h"

shared_ptr<Reflector> Reflector::ptr = nullptr;
REGISTER(SentryFactory);
REGISTER(InfantryFactory);
int main(int argc, char const *argv[])
{
    GLogWrapper glog(argv[0]);
    ifstream ifs;
    ifs.open("/home/wzx/sentry2/Phoenix.json");
    assert(ifs.is_open());
    Json::Reader reader;
    Json::Value root;
    if (!reader.parse(ifs, root, false))
    {
        return -1;
    }
    std::string name = root["name"].asString();
    shared_ptr<RMFactory> HDU_Phoenix_Factory((RMFactory*)Reflector::Instance()->CreateObject(name));
    // shared_ptr<RMFactory> HDU_Phoenix_Factory = make_shared<InfantryFactory>(); //根据不同车辆实例化工厂类
    shared_ptr<Phoenix> HDU_Phoenix = HDU_Phoenix_Factory->creatPhoenix(); //实例化对象

    std::thread produceThread  =  HDU_Phoenix->ProduceThread();  //生产者线程
    std::thread consumeThread = HDU_Phoenix->ConsumeThread(); //消费者线程
    std::thread senseThread    = HDU_Phoenix->SenseThread();  //从下位机读取数据的线程

    produceThread.join();
    consumeThread.join();
    senseThread.join();

    return 0;
} 
